<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="84px">
      <el-form-item label="项目编号" prop="projectId">
        <el-input v-model="queryParams.projectId" placeholder="请输入项目编号" clearable @clear="handleQuery" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="招标编号" prop="sectionId">
        <el-input v-model="queryParams.sectionId" placeholder="请输入招标编号" clearable @clear="handleQuery"  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="招标名称" prop="sectionName">
        <el-input v-model="queryParams.sectionName" placeholder="请输入招标名称" clearable @clear="handleQuery"  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="开标时间" prop="open">
        <el-date-picker clearable @clear="handleQuery" v-model="queryParams.open" type="date" value-format="yyyy-MM-dd" @change="handleQuery" placeholder="请选择开标时间"></el-date-picker>
      </el-form-item>
      <el-form-item label="开标地点" prop="openArea">
        <el-select v-model="queryParams.openArea" placeholder="请选择开标地点" clearable @clear="handleQuery" @change="handleQuery">
          <el-option
            v-for="dict in dict.type.sys_openarea"
            :key="dict.value"
            :label="dict.label"
            :value="Number(dict.value)">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="评标办法" prop="bidway">
        <el-select v-model="queryParams.bidway" placeholder="请选择评标办法" clearable @clear="handleQuery" @change="handleQuery">
          <el-option
            v-for="dict in dict.type.sys_bidway"
            :key="dict.value"
            :label="dict.label"
            :value="Number(dict.value)">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:section:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sectionList">
      <el-table-column label="序号" type="index" fixed width="55" align="center" />
      <el-table-column label="部门" fixed align="center" prop="projectInfo.deptName" show-overflow-tooltip />
      <el-table-column label="招标编号" align="center" prop="sectionId"  width="120" show-overflow-tooltip/>
      <el-table-column label="招标名称" align="center" prop="sectionName"  width="180" show-overflow-tooltip/>
      <el-table-column label="组织方式" align="center"  width="180">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_bidmethos" :value="scope.row.bidmethod"/>
        </template>
      </el-table-column>
      <el-table-column label="招标类别" align="center" prop="qualify" width="180" show-overflow-tooltip/>
      <el-table-column label="公告开始时间" align="center" prop="annBengin" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.annBengin, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="公告截止时间" align="center" prop="annEnd" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.annEnd, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开标时间" align="center" prop="open" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.open, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="估算金额" align="center" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.planprice }} 元</span>
        </template>
      </el-table-column>
      <el-table-column label="中标单位" align="center" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.planprice }} 元</span>
        </template>
      </el-table-column>
      <el-table-column label="中标金额" align="center" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.planprice }} 元</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['system:section:detail']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改标段列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="sectionForm" :model="form" label-width="96px">
        <el-row>
          <el-col :span="11">
            <el-form-item label="项目编号" prop="projectId">
              <el-input v-model="form.projectId" disabled placeholder="请输入项目编号" />
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="招标编号" prop="sectionId">
              <el-input v-model="form.sectionId" disabled placeholder="请输入招标编号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="招标名称" prop="sectionName">
              <el-input v-model="form.sectionName" disabled placeholder="请输入招标名称" />
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="组织方式" prop="bidmethod">
              <el-select v-model="form.bidmethod" disabled placeholder="请选择组织方式">
                <el-option
                  v-for="dict in dict.type.sys_bidmethos"
                  :key="dict.value"
                  :label="dict.label"
                  :value="Number(dict.value)">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="23">
            <el-form-item label="资质设置" prop="qualify">
              <el-input v-model="form.qualify" disabled type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="公告开始时间" title="公告开始时间" prop="annBengin">
              <el-date-picker clearable
                v-model="form.annBengin"
                disabled
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择公告开始时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="公告截止时间" title="公告截止时间" prop="annEnd">
              <el-date-picker clearable
                v-model="form.annEnd"
                disabled
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择公告截止时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="开标时间" prop="open">
              <el-date-picker clearable
                v-model="form.open"
                disabled
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择开标时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="开标地点" prop="openArea">
              <el-select v-model="form.openArea" disabled placeholder="请选择开标地点">
                <el-option
                  v-for="dict in dict.type.sys_openarea"
                  :key="dict.value"
                  :label="dict.label"
                  :value="Number(dict.value)">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="评标办法" prop="bidway">
              <el-select v-model="form.bidway" disabled placeholder="请选择评标办法">
                <el-option
                  v-for="dict in dict.type.sys_bidway"
                  :key="dict.value"
                  :label="dict.label"
                  :value="Number(dict.value)">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="估算价" prop="planprice">
              <el-input class="pirce" v-model="form.planprice" disabled placeholder="请输入估算价" /> 元
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="open = false">确 定</el-button>
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listSection, getSection } from "@/api/projectManage/sectionList";

export default {
  name: "Section",
  dicts: ['sys_bidmethos', 'sys_openarea', 'sys_bidway', 'is_switch'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 标段列表表格数据
      sectionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        sectionId: null,
        sectionName: null,
        bidmethod: null,
        qualify: null,
        annBengin: null,
        annEnd: null,
        open: null,
        openArea: null,
        bidway: null,
        planprice: null,
        online: null
      },
      // 表单参数
      form: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询标段列表列表 */
    getList() {
      this.loading = true;
      listSection(this.queryParams).then(response => {
        this.sectionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectId: null,
        sectionId: null,
        sectionName: null,
        bidmethod: null,
        qualify: null,
        annBengin: null,
        annEnd: null,
        open: null,
        openArea: null,
        bidway: null,
        planprice: null,
        online: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/section/export', {
        ...this.queryParams
      }, `section_${new Date().getTime()}.xlsx`)
    },
    handleDetail(row) {
      this.title = "查看标段"
      getSection(row.id).then(response => {
        this.form = response.data
        this.open = true
      });
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog{
  .el-date-editor, .el-input, .el-select {
    width: 100%;
  }
  .el-dialog__body {
    padding: 30px 10px 30px 30px;
  }
  .el-form-item__label {
    max-width: 100px; /* 你可以根据需要调整这个值 */
    white-space: nowrap; /* 防止文字换行 */
    overflow: hidden; /* 超出部分隐藏 */
    text-overflow: ellipsis; /* 文字溢出时显示省略号 */
  }
  .is-disabled{
    .el-textarea__inner, .el-input__inner {
      color: #333333;
    }
    .el-radio__label {
      color: #333333;
    }
    .el-radio__inner {
      border-color: #333333;
      &::after {
        background: #333333;
      }
    }
  }
  .pirce {
    width: 94%;
  }
}
</style>
